#ifndef MEMORYMANAGER_H
#define MEMORYMANAGER_H

#include "machine.h"
#include "filesys.h"

#define MEM_SIZE 4096
#define NUM_SWAP_PAGES 512 // in pages

enum { MM_ALLOCATION_FAILED = -1};

class MemoryManager
{
public:
    MemoryManager();
    ~MemoryManager();
    int     allocateSwapPage();
	int		allocatePhysicalPage();
    void    releasePage(int, int);
	int		getSwapPageLocation(int swapPageIndex);
	void	writePage(int physicalPage, int swapPage);
	void	loadPage(int physicalPage, int swapPage);
	void 	copyPageFromMem(int fromPhysPage, int toSwapPage);
	void	copyPageFromSwap(int fromSwappage, int toSwapPage);
	void	writeBufferToSwapPage(char *buffer, int swapPage);


private:
	int numPhysicalPages;
	
	// array of bools representing which pages are free
    bool *swapPageInUse;
	bool *physicalPageInUse;

	int swapPagesInUse;
	
	OpenFile *swapFile;
};

#endif // MEMORYMANAGER_H
